package com.loadmore.baselibrary;

import android.app.Activity;
import android.app.Application;

import com.loadmore.baselibrary.util.InitUtil;

import java.util.Stack;

/**
 * @author sunleilei
 * @date 2017/5/14
 */

public class App extends Application {
    public static App application;
    private static Stack<Activity> activities = new Stack<>();
    @Override
    public void onCreate() {
        super.onCreate();
        application = this;
        init();
    }

    public void init() {
        InitUtil.initScreen(this);
    }

    public static App getApplication() {
        return application;
    }

    public void addActivity(Activity activity) {
        activities.push(activity);
    }

    public void removeActivity() {
        activities.pop();
    }

    @Override
    public void onTrimMemory(int level) {
        super.onTrimMemory(level);
        switch (level) {
        }
    }

    public int getActivityCount() {
        return activities.size();
    }

    public void exitApp() {
        for (int i = 0; i < activities.size(); i++) {
            Activity activity = activities.get(i);
            activity.finish();
        }
    }
}
